package top.jojoace.GlobalExceptionAdvice_And_AutoURI.core.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * <h3>读取配置文件，并注入到属性中</h3><br>
 *
 *
 * <h1>@PropertySource(value = "classpath:XXX/XXX.properties",encoding = "配置文件编码")</h1>
 * <h2>读取 exception-code.properties配置文件</h2>
 * <h2>配置文件中的 参数名 应与 属性名 一致,同时getter和setter</h2><br><br><br>
 *
 * <h1>@ConfigurationProperties(prefix = "XXX")</h1>
 * <h2>设置配置文件中的参数前缀</h2>
 *
 */
@ConfigurationProperties(prefix = "exception")
@PropertySource(value = "classpath:config/exception-code.properties",encoding = "GBK")
@Component
public class ExceptionCodeConfiguration {

    private Map<Integer,String> codes = new HashMap<>();

    public String getMessage(int code){
        String message = codes.get(code);
        return message;
    }


    public Map<Integer, String> getCodes() {
        return codes;
    }

    public void setCodes(Map<Integer, String> codes) {
        this.codes = codes;
    }
}
